﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using YArchitech.LIB;

namespace YArchitech.Plumbing
{
	public class SystemDataOperation
	{
		public SystemDataOperation(string xmlPath)
		{
			if (!File.Exists(xmlPath))
			{
				File.Copy(Path.Combine(Product.DataLocation, "GeothermalCoil.xml"), xmlPath);
			}
			this.xmlDoc = XMLOperating.LoadXml(xmlPath);
		}

		public bool CheckXmlFile()
		{
			XmlNode xmlNode = this.xmlDoc.SelectSingleNode(this.rootName);
			if (xmlNode == null)
			{
				return false;
			}
			XmlNodeList childNodes = xmlNode.ChildNodes;
			return childNodes.Count == 2 && !(childNodes[0].Name != "SystemSetting") && !(childNodes[1].Name != "BuildSystem");
		}

		public OptionData GetOptionData()
		{
			OptionData optionData = new OptionData();
			foreach (object obj in this.xmlDoc.SelectSingleNode(this.rootName).FirstChild.ChildNodes)
			{
				XmlNode xmlNode = (XmlNode)obj;
				string name = xmlNode.Name;
				uint num = YArchitech.Revit.PrivateImplementationDetails.ComputeStringHash(name);
				if (num <= 873509818u)
				{
					if (num <= 373802935u)
					{
						if (num != 182836306u)
						{
							if (num == 373802935u)
							{
								if (name == "DPCValvePosition")
								{
									optionData.DPValvePosition = Convert.ToInt32(xmlNode.InnerText);
								}
							}
						}
						else if (name == "RiserPipe")
						{
							optionData.RiserPipeInter = Convert.ToInt32(xmlNode.InnerText);
						}
					}
					else if (num != 669849211u)
					{
						if (num != 817867405u)
						{
							if (num == 873509818u)
							{
								if (name == "LocalResist")
								{
									optionData.Resistance = Convert.ToDouble(xmlNode.InnerText);
								}
							}
						}
						else if (name == "PressTCValve")
						{
							optionData.DiffTCValve = Convert.ToDouble(xmlNode.InnerText);
						}
					}
					else if (name == "SupplyTemper")
					{
						optionData.TemperSupply = Convert.ToDouble(xmlNode.InnerText);
					}
				}
				else if (num <= 2720717305u)
				{
					if (num != 2387656034u)
					{
						if (num != 2661243761u)
						{
							if (num == 2720717305u)
							{
								if (name == "PressPCValve")
								{
									optionData.DiffDPValve = Convert.ToDouble(xmlNode.InnerText);
								}
							}
						}
						else if (name == "LocalCoef")
						{
							optionData.ResistanceLocal = Convert.ToDouble(xmlNode.InnerText);
						}
					}
					else if (name == "ReturnTemper")
					{
						optionData.TemperReturn = Convert.ToDouble(xmlNode.InnerText);
					}
				}
				else if (num != 3193575323u)
				{
					if (num != 3393614922u)
					{
						if (num == 3958409460u)
						{
							if (name == "MainPipe")
							{
								optionData.MainPipeInter = Convert.ToInt32(xmlNode.InnerText);
							}
						}
					}
					else if (name == "Floors")
					{
						IList<HYFloor> list = new List<HYFloor>();
						foreach (object obj2 in xmlNode.ChildNodes)
						{
							XmlNode xmlNode2 = (XmlNode)obj2;
							list.Add(new HYFloor
							{
								Number = Convert.ToInt32(xmlNode2.Attributes[SystemDataOperation.SetValueName.Number.ToString()].Value),
								Height = Convert.ToDouble(xmlNode2.Attributes[SystemDataOperation.SetValueName.Height.ToString()].Value)
							});
						}
						optionData.FloorList = list;
					}
				}
				else if (name == "FloorNum")
				{
					optionData.FloorNum = Convert.ToInt32(xmlNode.InnerText);
				}
			}
			optionData.MaterialInternal = 1;
			return optionData;
		}

		public InBuildSystem GetBuildSystem(OptionData option)
		{
			InBuildSystem inBuildSystem = new InBuildSystem();
			XmlNode parentNode = this.xmlDoc.SelectSingleNode(this.rootName);
			XmlNode nodeByChildName = this.GetNodeByChildName(parentNode, SystemDataOperation.SystemNodeName.BuildSystem.ToString());
			if (nodeByChildName == null)
			{
				throw new Exception("读取系统数据出错，可能数据丢失或储存格式有误！");
			}
			inBuildSystem.SerialNum = this.GetStringValue(nodeByChildName, SystemDataOperation.SetValueName.SerialNum.ToString());
			inBuildSystem.RiserPipeNum = this.GetIntValue(nodeByChildName, SystemDataOperation.SetValueName.RiserPipeNum.ToString());
			inBuildSystem.TotalLoad = this.GetDoubleValue(nodeByChildName, SystemDataOperation.SetValueName.Load.ToString());
			inBuildSystem.TotalFlow = this.GetDoubleValue(nodeByChildName, SystemDataOperation.SetValueName.Flow.ToString());
			inBuildSystem.TotalResistance = this.GetDoubleValue(nodeByChildName, SystemDataOperation.SetValueName.Resistance.ToString());
			inBuildSystem.SupplyTmPipe = this.GetPipeListIntoNode(nodeByChildName, SystemDataOperation.SystemNodeName.MSupplyPipes.ToString());
			inBuildSystem.ReturnTmPipe = this.GetPipeListIntoNode(nodeByChildName, SystemDataOperation.SystemNodeName.MReturnPipes.ToString());
			inBuildSystem.SrpSystems = this.GetShareRPipeSystems(nodeByChildName, SystemDataOperation.SystemNodeName.ShareRPipes.ToString(), option);
			inBuildSystem.PipeConnForm = option.MainPipeInter;
			return inBuildSystem;
		}

		public IList<ShareRPipeSystem> GetShareRPipeSystems(XmlNode parentNode, string nodeName, OptionData option)
		{
			IList<ShareRPipeSystem> list = new List<ShareRPipeSystem>();
			XmlNode nodeByChildName = this.GetNodeByChildName(parentNode, nodeName);
			if (nodeByChildName == null)
			{
				throw new Exception("读取立管系统出错，可能数据丢失或储存方式不正确！");
			}
			if (nodeByChildName.ChildNodes == null || nodeByChildName.ChildNodes.Count < 1)
			{
				return list;
			}
			foreach (object obj in nodeByChildName.ChildNodes)
			{
				XmlNode xmlNode = (XmlNode)obj;
				list.Add(new ShareRPipeSystem
				{
					PreSerialNum = this.GetStringValue(xmlNode, SystemDataOperation.SetValueName.PreSerialNum.ToString()),
					SerialNum = this.GetStringValue(xmlNode, SystemDataOperation.SetValueName.SerialNum.ToString()),
					RateUnbalance = this.GetDoubleValue(xmlNode, SystemDataOperation.SetValueName.RateUnbalance.ToString()),
					SupplyPipes = this.GetPipeListIntoNode(xmlNode, SystemDataOperation.SystemNodeName.RSupplyPipes.ToString()),
					ReturnPipes = this.GetPipeListIntoNode(xmlNode, SystemDataOperation.SystemNodeName.RReturnPipes.ToString()),
					FloorSystems = this.GetFloorSystems(xmlNode, SystemDataOperation.SystemNodeName.FloorSystems.ToString(), option),
					PipeConnForm = option.RiserPipeInter
				});
			}
			return list;
		}

		public IList<FloorSystem> GetFloorSystems(XmlNode parentNode, string nodeName, OptionData option)
		{
			IList<FloorSystem> list = new List<FloorSystem>();
			XmlNode nodeByChildName = this.GetNodeByChildName(parentNode, nodeName);
			if (nodeByChildName == null)
			{
				throw new Exception("读取楼层系统出错，可能数据丢失或储存方式不正确！");
			}
			if (nodeByChildName.ChildNodes == null || nodeByChildName.ChildNodes.Count < 1)
			{
				return list;
			}
			foreach (object obj in nodeByChildName.ChildNodes)
			{
				XmlNode xmlNode = (XmlNode)obj;
				list.Add(new FloorSystem
				{
					PreSerialNum = this.GetStringValue(xmlNode, SystemDataOperation.SetValueName.PreSerialNum.ToString()),
					SerialNum = this.GetStringValue(xmlNode, SystemDataOperation.SetValueName.SerialNum.ToString()),
					IndoorNum = this.GetIntValue(xmlNode, SystemDataOperation.SetValueName.IndoorNum.ToString()),
					RateUnbalance = this.GetDoubleValue(xmlNode, SystemDataOperation.SetValueName.RateUnbalance.ToString()),
					IndoorSystems = this.GetIndoorSystems(xmlNode, option)
				});
			}
			return list;
		}

		public IList<IndoorSystem> GetIndoorSystems(XmlNode parentNode, OptionData option)
		{
			IList<IndoorSystem> list = new List<IndoorSystem>();
			if (parentNode == null || parentNode.ChildNodes == null || parentNode.ChildNodes.Count < 1)
			{
				return list;
			}
			foreach (object obj in parentNode.ChildNodes)
			{
				XmlNode xmlNode = (XmlNode)obj;
				IndoorSystem indoorSystem = new IndoorSystem();
				indoorSystem.PreSerialNum = this.GetStringValue(xmlNode, SystemDataOperation.SetValueName.PreSerialNum.ToString());
				indoorSystem.SerialNum = this.GetStringValue(xmlNode, SystemDataOperation.SetValueName.SerialNum.ToString());
				indoorSystem.CircleNum = this.GetIntValue(xmlNode, SystemDataOperation.SetValueName.CircleNum.ToString());
				indoorSystem.RateUnbalance = this.GetDoubleValue(xmlNode, SystemDataOperation.SetValueName.RateUnbalance.ToString());
				indoorSystem.DPressCapital = this.GetDoubleValue(xmlNode, SystemDataOperation.SetValueName.DPressCapital.ToString());
				indoorSystem.DPressControl = this.GetDoubleValue(xmlNode, SystemDataOperation.SetValueName.DPressControl.ToString());
				if (indoorSystem.CircleNum > 1)
				{
					indoorSystem.ReturnMPipe = this.GetPipeIntoNode(xmlNode, SystemDataOperation.SystemNodeName.ReturnPipe.ToString());
					indoorSystem.SupplyMPipe = this.GetPipeIntoNode(xmlNode, SystemDataOperation.SystemNodeName.SupplyPipe.ToString());
				}
				indoorSystem.CirclePipes = this.GetCirclePipes(xmlNode, SystemDataOperation.SystemNodeName.CircleSystems.ToString(), option);
				list.Add(indoorSystem);
			}
			return list;
		}

		private IList<CirclePipe> GetCirclePipes(XmlNode parentNode, string childName, OptionData option)
		{
			IList<CirclePipe> list = new List<CirclePipe>();
			XmlNode nodeByChildName = this.GetNodeByChildName(parentNode, childName);
			if (nodeByChildName == null)
			{
				throw new Exception("读取环路系统出错，可能数据丢失或储存方式不正确！");
			}
			if (nodeByChildName.ChildNodes == null || nodeByChildName.ChildNodes.Count < 1)
			{
				return list;
			}
			foreach (object obj in nodeByChildName.ChildNodes)
			{
				XmlNode node = (XmlNode)obj;
				CirclePipe item = new CirclePipe();
				item = this.GetCirclePipeByNode(node, option);
				list.Add(item);
			}
			return list;
		}

		private XmlNode GetNodeByChildName(XmlNode parentNode, string childName)
		{
			XmlNode result = null;
			if (parentNode == null || parentNode.ChildNodes == null || parentNode.ChildNodes.Count < 1)
			{
				return result;
			}
			foreach (object obj in parentNode.ChildNodes)
			{
				XmlNode xmlNode = (XmlNode)obj;
				if (xmlNode.Name == childName)
				{
					result = xmlNode;
					break;
				}
			}
			return result;
		}

		private IList<HYPipeData> GetPipeListIntoNode(XmlNode parentNode, string childName)
		{
			IList<HYPipeData> list = new List<HYPipeData>();
			XmlNode nodeByChildName = this.GetNodeByChildName(parentNode, childName);
			if (nodeByChildName == null || nodeByChildName.ChildNodes == null || nodeByChildName.ChildNodes.Count < 1)
			{
				return list;
			}
			foreach (object obj in nodeByChildName.ChildNodes)
			{
				XmlNode node = (XmlNode)obj;
				list.Add(new HYPipeData
				{
					PreSerialNum = this.GetStringValue(node, SystemDataOperation.SetValueName.PreSerialNum.ToString()),
					SerialNum = this.GetStringValue(node, SystemDataOperation.SetValueName.SerialNum.ToString()),
					Flow = this.GetDoubleValue(node, SystemDataOperation.SetValueName.Flow.ToString()),
					Diameter = this.GetIntValue(node, SystemDataOperation.SetValueName.Diameter.ToString()),
					Length = this.GetDoubleValue(node, SystemDataOperation.SetValueName.Length.ToString()),
					Speed = this.GetDoubleValue(node, SystemDataOperation.SetValueName.Speed.ToString()),
					ResistanceFrict = this.GetDoubleValue(node, SystemDataOperation.SetValueName.ResistanceFrict.ToString()),
					DragForce = this.GetDoubleValue(node, SystemDataOperation.SetValueName.DragForce.ToString()),
					ResistanceLocal = this.GetDoubleValue(node, SystemDataOperation.SetValueName.ResistanceLocal.ToString()),
					Resistance = this.GetDoubleValue(node, SystemDataOperation.SetValueName.Resistance.ToString()),
					ValvesList = this.GetValveList(node)
				});
			}
			return list;
		}

		private HYPipeData GetPipeIntoNode(XmlNode parentNode, string childName)
		{
			HYPipeData hypipeData = new HYPipeData();
			XmlNode nodeByChildName = this.GetNodeByChildName(parentNode, childName);
			if (nodeByChildName == null)
			{
				return hypipeData;
			}
			hypipeData.PreSerialNum = this.GetStringValue(nodeByChildName, SystemDataOperation.SetValueName.PreSerialNum.ToString());
			hypipeData.SerialNum = this.GetStringValue(nodeByChildName, SystemDataOperation.SetValueName.SerialNum.ToString());
			hypipeData.Flow = this.GetDoubleValue(nodeByChildName, SystemDataOperation.SetValueName.Flow.ToString());
			hypipeData.OutDiameter = this.GetStringValue(nodeByChildName, SystemDataOperation.SetValueName.OutDiameter.ToString());
			hypipeData.Length = this.GetDoubleValue(nodeByChildName, SystemDataOperation.SetValueName.Length.ToString());
			hypipeData.Speed = this.GetDoubleValue(nodeByChildName, SystemDataOperation.SetValueName.Speed.ToString());
			hypipeData.ResistanceFrict = this.GetDoubleValue(nodeByChildName, SystemDataOperation.SetValueName.ResistanceFrict.ToString());
			hypipeData.DragForce = this.GetDoubleValue(nodeByChildName, SystemDataOperation.SetValueName.DragForce.ToString());
			hypipeData.ResistanceLocal = this.GetDoubleValue(nodeByChildName, SystemDataOperation.SetValueName.ResistanceLocal.ToString());
			hypipeData.Resistance = this.GetDoubleValue(nodeByChildName, SystemDataOperation.SetValueName.Resistance.ToString());
			hypipeData.ValvesList = this.GetValveList(nodeByChildName);
			return hypipeData;
		}

		private CirclePipe GetCirclePipeByNode(XmlNode node, OptionData option)
		{
			CirclePipe circlePipe = new CirclePipe();
			if (node == null)
			{
				return circlePipe;
			}
			circlePipe.PreSerialNum = this.GetStringValue(node, SystemDataOperation.SetValueName.PreSerialNum.ToString());
			circlePipe.SerialNum = this.GetStringValue(node, SystemDataOperation.SetValueName.SerialNum.ToString());
			circlePipe.Flow = this.GetDoubleValue(node, SystemDataOperation.SetValueName.Flow.ToString());
			circlePipe.Load = this.GetDoubleValue(node, SystemDataOperation.SetValueName.Load.ToString());
			circlePipe.RateUnbalance = this.GetDoubleValue(node, SystemDataOperation.SetValueName.RateUnbalance.ToString());
			HYPipeData hypipeData = new HYPipeData();
			hypipeData.PreSerialNum = this.GetStringValue(node, SystemDataOperation.SetValueName.PreSerialNum.ToString());
			hypipeData.SerialNum = this.GetStringValue(node, SystemDataOperation.SetValueName.SerialNum.ToString());
			hypipeData.Flow = this.GetDoubleValue(node, SystemDataOperation.SetValueName.Flow.ToString());
			hypipeData.Load = this.GetDoubleValue(node, SystemDataOperation.SetValueName.Load.ToString());
			hypipeData.OutDiameter = this.GetStringValue(node, SystemDataOperation.SetValueName.OutDiameter.ToString());
			hypipeData.Length = this.GetDoubleValue(node, SystemDataOperation.SetValueName.Length.ToString());
			hypipeData.Speed = this.GetDoubleValue(node, SystemDataOperation.SetValueName.Speed.ToString());
			hypipeData.ResistanceFrict = this.GetDoubleValue(node, SystemDataOperation.SetValueName.ResistanceFrict.ToString());
			hypipeData.Resistance = this.GetDoubleValue(node, SystemDataOperation.SetValueName.Resistance.ToString());
			hypipeData.ValvesList = this.GetValveList(node);
			circlePipe.TemperSupply = option.TemperSupply;
			circlePipe.TemperReturn = option.TemperReturn;
			circlePipe.PipeData = hypipeData;
			return circlePipe;
		}

		private IList<ValveAndFitting> GetValveList(XmlNode node)
		{
			IList<ValveAndFitting> list = new List<ValveAndFitting>();
			if (node == null || node.ChildNodes == null || node.ChildNodes.Count < 1)
			{
				return list;
			}
			foreach (object obj in node.ChildNodes)
			{
				XmlNode xmlNode = (XmlNode)obj;
				if (xmlNode.InnerText == "null")
				{
					return list;
				}
				double doubleValue = this.GetDoubleValue(xmlNode, ValveName.Bend.ToString());
				if (doubleValue > 0.0)
				{
					ValveAndFitting item = new ValveAndFitting(this.GetValveStringName(ValveName.Bend), doubleValue);
					list.Add(item);
				}
				doubleValue = this.GetDoubleValue(xmlNode, ValveName.Casing.ToString());
				if (doubleValue > 0.0)
				{
					ValveAndFitting item = new ValveAndFitting(this.GetValveStringName(ValveName.Casing), doubleValue);
					list.Add(item);
				}
				doubleValue = this.GetDoubleValue(xmlNode, ValveName.Elbow.ToString());
				if (doubleValue > 0.0)
				{
					ValveAndFitting item = new ValveAndFitting(this.GetValveStringName(ValveName.Elbow), doubleValue);
					list.Add(item);
				}
				doubleValue = this.GetDoubleValue(xmlNode, ValveName.Expansion.ToString());
				if (doubleValue > 0.0)
				{
					ValveAndFitting item = new ValveAndFitting(this.GetValveStringName(ValveName.Expansion), doubleValue);
					list.Add(item);
				}
				doubleValue = this.GetDoubleValue(xmlNode, ValveName.Gate.ToString());
				if (doubleValue > 0.0)
				{
					ValveAndFitting item = new ValveAndFitting(this.GetValveStringName(ValveName.Gate), doubleValue);
					list.Add(item);
				}
				doubleValue = this.GetDoubleValue(xmlNode, ValveName.Other.ToString());
				if (doubleValue > 0.0)
				{
					ValveAndFitting item = new ValveAndFitting(this.GetValveStringName(ValveName.Other), doubleValue);
					list.Add(item);
				}
				doubleValue = this.GetDoubleValue(xmlNode, ValveName.Raditor.ToString());
				if (doubleValue > 0.0)
				{
					ValveAndFitting item = new ValveAndFitting(this.GetValveStringName(ValveName.Raditor), doubleValue);
					list.Add(item);
				}
				doubleValue = this.GetDoubleValue(xmlNode, ValveName.RodStop.ToString());
				if (doubleValue > 0.0)
				{
					ValveAndFitting item = new ValveAndFitting(this.GetValveStringName(ValveName.RodStop), doubleValue);
					list.Add(item);
				}
				doubleValue = this.GetDoubleValue(xmlNode, ValveName.Square.ToString());
				if (doubleValue > 0.0)
				{
					ValveAndFitting item = new ValveAndFitting(this.GetValveStringName(ValveName.Square), doubleValue);
					list.Add(item);
				}
				doubleValue = this.GetDoubleValue(xmlNode, ValveName.Stop.ToString());
				if (doubleValue > 0.0)
				{
					ValveAndFitting item = new ValveAndFitting(this.GetValveStringName(ValveName.Stop), doubleValue);
					list.Add(item);
				}
			}
			return list;
		}

		private string GetValveStringName(ValveName valveName)
		{
			int num = (int)Enum.Parse(typeof(ValveName), valveName.ToString());
			return ((ValveString)Enum.Parse(typeof(ValveString), num.ToString())).ToString();
		}

		private string GetStringValue(XmlNode node, string attName)
		{
			string result = "";
			try
			{
				if (node.Attributes != null && node.Attributes[attName] != null)
				{
					result = node.Attributes[attName].Value;
				}
			}
			catch (Exception)
			{
				return result;
			}
			return result;
		}

		private double GetDoubleValue(XmlNode node, string attName)
		{
			double result = 0.0;
			try
			{
				if (node.Attributes != null && node.Attributes[attName].Value != "")
				{
					result = Convert.ToDouble(node.Attributes[attName].Value);
				}
			}
			catch (Exception)
			{
				return result;
			}
			return result;
		}

		private int GetIntValue(XmlNode node, string attName)
		{
			int result = 0;
			try
			{
				if (node.Attributes != null)
				{
					result = Convert.ToInt32(node.Attributes[attName].Value);
				}
			}
			catch (Exception)
			{
				return result;
			}
			return result;
		}

		public bool SaveXml(string xmlPath, OptionData option, InBuildSystem buildSystem)
		{
			bool result;
			try
			{
				this.xmlDoc = new XmlDocument();
				XmlDeclaration newChild = this.xmlDoc.CreateXmlDeclaration("1.0", "gb2312", "");
				XmlNode xmlNode = this.xmlDoc.CreateElement(this.rootName);
				this.xmlDoc.AppendChild(newChild);
				this.xmlDoc.AppendChild(xmlNode);
				XmlNode newChild2 = this.CreateSystemSetting(option);
				xmlNode.AppendChild(newChild2);
				XmlElement newChild3 = this.CreateBuildSystem(buildSystem);
				xmlNode.AppendChild(newChild3);
				this.xmlDoc.Save(xmlPath);
				result = true;
			}
			catch (Exception)
			{
				result = false;
			}
			return result;
		}

		private XmlNode CreateSystemSetting(OptionData option)
		{
			XmlNode xmlNode = this.xmlDoc.CreateElement("SystemSetting");
			this.CreateNode(SystemDataOperation.SettingNodeName.MainPipe.ToString(), option.MainPipeInter.ToString(), xmlNode);
			this.CreateNode(SystemDataOperation.SettingNodeName.RiserPipe.ToString(), option.RiserPipeInter.ToString(), xmlNode);
			this.CreateNode(SystemDataOperation.SettingNodeName.SupplyTemper.ToString(), option.TemperSupply.ToString(), xmlNode);
			this.CreateNode(SystemDataOperation.SettingNodeName.ReturnTemper.ToString(), option.TemperReturn.ToString(), xmlNode);
			this.CreateNode(SystemDataOperation.SettingNodeName.FloorNum.ToString(), option.FloorNum.ToString(), xmlNode);
			XmlNode newChild = this.CreateFloors(option);
			xmlNode.AppendChild(newChild);
			this.CreateNode(SystemDataOperation.SettingNodeName.LocalCoef.ToString(), option.ResistanceLocal.ToString(), xmlNode);
			this.CreateNode(SystemDataOperation.SettingNodeName.LocalResist.ToString(), option.Resistance.ToString(), xmlNode);
			this.CreateNode(SystemDataOperation.SettingNodeName.DPCValvePosition.ToString(), option.DPValvePosition.ToString(), xmlNode);
			this.CreateNode(SystemDataOperation.SettingNodeName.PressPCValve.ToString(), option.DiffDPValve.ToString(), xmlNode);
			this.CreateNode(SystemDataOperation.SettingNodeName.PressTCValve.ToString(), option.DiffTCValve.ToString(), xmlNode);
			return xmlNode;
		}

		private XmlNode CreateFloors(OptionData option)
		{
			XmlNode xmlNode = this.xmlDoc.CreateElement(SystemDataOperation.SettingNodeName.Floors.ToString());
			for (int i = 0; i < option.FloorNum; i++)
			{
				XmlElement xmlElement = this.xmlDoc.CreateElement(SystemDataOperation.SettingNodeName.Floor.ToString());
				xmlElement.SetAttribute(SystemDataOperation.SetValueName.Number.ToString(), option.FloorList[i].Number.ToString());
				xmlElement.SetAttribute(SystemDataOperation.SetValueName.Height.ToString(), option.FloorList[i].Height.ToString());
				xmlNode.AppendChild(xmlElement);
			}
			return xmlNode;
		}

		private void CreateNode(string name, string value, XmlNode xmlParantNode)
		{
			XmlNode xmlNode = this.xmlDoc.CreateElement(name);
			xmlNode.InnerText = value;
			xmlParantNode.AppendChild(xmlNode);
		}

		private XmlElement CreateBuildSystem(InBuildSystem buildSystem)
		{
			XmlElement xmlElement = this.xmlDoc.CreateElement("BuildSystem");
			xmlElement.SetAttribute(SystemDataOperation.SetValueName.RiserPipeNum.ToString(), buildSystem.RiserPipeNum.ToString());
			xmlElement.SetAttribute(SystemDataOperation.SetValueName.Load.ToString(), buildSystem.TotalLoad.ToString());
			xmlElement.SetAttribute(SystemDataOperation.SetValueName.Flow.ToString(), buildSystem.TotalFlow.ToString());
			xmlElement.SetAttribute(SystemDataOperation.SetValueName.Resistance.ToString(), buildSystem.TotalResistance.ToString());
			XmlElement newChild = this.CreatePipes(buildSystem.SupplyTmPipe, "MSupplyPipes");
			xmlElement.AppendChild(newChild);
			XmlElement newChild2 = this.CreatePipes(buildSystem.ReturnTmPipe, "MReturnPipes");
			xmlElement.AppendChild(newChild2);
			XmlElement newChild3 = this.CreateShareRPipes(buildSystem.SrpSystems);
			xmlElement.AppendChild(newChild3);
			return xmlElement;
		}

		private XmlElement CreatePipes(IList<HYPipeData> pipeDatas, string name)
		{
			XmlElement xmlElement = this.xmlDoc.CreateElement(name);
			foreach (HYPipeData hypipeData in pipeDatas)
			{
				XmlElement xmlElement2 = this.xmlDoc.CreateElement("Pipe");
				xmlElement2.SetAttribute(SystemDataOperation.SetValueName.Flow.ToString(), hypipeData.Flow.ToString());
				xmlElement2.SetAttribute(SystemDataOperation.SetValueName.Diameter.ToString(), hypipeData.Diameter.ToString());
				xmlElement2.SetAttribute(SystemDataOperation.SetValueName.Length.ToString(), hypipeData.Length.ToString());
				xmlElement2.SetAttribute(SystemDataOperation.SetValueName.Speed.ToString(), hypipeData.Speed.ToString());
				xmlElement2.SetAttribute(SystemDataOperation.SetValueName.ResistanceFrict.ToString(), hypipeData.ResistanceFrict.ToString());
				xmlElement2.SetAttribute(SystemDataOperation.SetValueName.DragForce.ToString(), hypipeData.DragForce.ToString());
				xmlElement2.SetAttribute(SystemDataOperation.SetValueName.ResistanceLocal.ToString(), hypipeData.ResistanceLocal.ToString());
				xmlElement2.SetAttribute(SystemDataOperation.SetValueName.Resistance.ToString(), hypipeData.Resistance.ToString());
				XmlElement newChild = this.CreatePipeValve(hypipeData);
				xmlElement2.AppendChild(newChild);
				xmlElement.AppendChild(xmlElement2);
			}
			return xmlElement;
		}

		private XmlElement CreatePipeValve(HYPipeData pipeData)
		{
			XmlElement xmlElement = this.xmlDoc.CreateElement("Valve");
			xmlElement.SetAttribute(ValveName.Gate.ToString(), this.GetValveNum(pipeData, ValveString.闸阀.ToString()));
			xmlElement.SetAttribute(ValveName.Stop.ToString(), this.GetValveNum(pipeData, ValveString.截止阀.ToString()));
			xmlElement.SetAttribute(ValveName.RodStop.ToString(), this.GetValveNum(pipeData, ValveString.斜杆截止阀.ToString()));
			xmlElement.SetAttribute(ValveName.Elbow.ToString(), this.GetValveNum(pipeData, ValveString.弯头.ToString()));
			xmlElement.SetAttribute(ValveName.Bend.ToString(), this.GetValveNum(pipeData, ValveString.乙字弯.ToString()));
			xmlElement.SetAttribute(ValveName.Expansion.ToString(), this.GetValveNum(pipeData, ValveString.扩弯.ToString()));
			xmlElement.SetAttribute(ValveName.Square.ToString(), this.GetValveNum(pipeData, ValveString.方形补偿器.ToString()));
			xmlElement.SetAttribute(ValveName.Casing.ToString(), this.GetValveNum(pipeData, ValveString.套管补偿器.ToString()));
			xmlElement.SetAttribute(ValveName.Raditor.ToString(), this.GetValveNum(pipeData, ValveString.散热器.ToString()));
			xmlElement.SetAttribute(ValveName.Other.ToString(), this.GetValveNum(pipeData, ValveString.其他.ToString()));
			if (pipeData.ValvesList.Count == 0)
			{
				xmlElement.InnerText = "null";
			}
			else
			{
				xmlElement.InnerText = "";
			}
			return xmlElement;
		}

		private string GetValveNum(HYPipeData pipeData, string strValveName)
		{
			foreach (ValveAndFitting valveAndFitting in pipeData.ValvesList)
			{
				if (valveAndFitting.VFName == strValveName)
				{
					return valveAndFitting.Value.ToString();
				}
			}
			return "";
		}

		private XmlElement CreateShareRPipes(IList<ShareRPipeSystem> listSrpSystems)
		{
			XmlElement xmlElement = this.xmlDoc.CreateElement("ShareRPipes");
			foreach (ShareRPipeSystem shareRPipeSystem in listSrpSystems)
			{
				XmlElement xmlElement2 = this.xmlDoc.CreateElement("RiserPipe");
				xmlElement2.SetAttribute(SystemDataOperation.SetValueName.RateUnbalance.ToString(), shareRPipeSystem.RateUnbalance.ToString());
				XmlElement newChild = this.CreatePipes(shareRPipeSystem.SupplyPipes, "RSupplyPipes");
				xmlElement2.AppendChild(newChild);
				XmlElement newChild2 = this.CreatePipes(shareRPipeSystem.ReturnPipes, "RReturnPipes");
				xmlElement2.AppendChild(newChild2);
				XmlElement newChild3 = this.CreateFloorSystems(shareRPipeSystem.FloorSystems);
				xmlElement2.AppendChild(newChild3);
				xmlElement.AppendChild(xmlElement2);
			}
			return xmlElement;
		}

		private XmlElement CreateFloorSystems(IList<FloorSystem> listFloorSystems)
		{
			XmlElement xmlElement = this.xmlDoc.CreateElement("FloorSystems");
			foreach (FloorSystem floorSystem in listFloorSystems)
			{
				XmlElement xmlElement2 = this.xmlDoc.CreateElement("Floor");
				xmlElement2.SetAttribute(SystemDataOperation.SetValueName.IndoorNum.ToString(), floorSystem.IndoorNum.ToString());
				xmlElement2.SetAttribute(SystemDataOperation.SetValueName.RateUnbalance.ToString(), floorSystem.RateUnbalance.ToString());
				foreach (IndoorSystem indoorSystem in floorSystem.IndoorSystems)
				{
					XmlElement newChild = this.CreateIndoorSystems(indoorSystem);
					xmlElement2.AppendChild(newChild);
				}
				xmlElement.AppendChild(xmlElement2);
			}
			return xmlElement;
		}

		private XmlElement CreateIndoorSystems(IndoorSystem indoorSystem)
		{
			XmlElement xmlElement = this.xmlDoc.CreateElement("IndoorSystem");
			xmlElement.SetAttribute(SystemDataOperation.SetValueName.CircleNum.ToString(), indoorSystem.CircleNum.ToString());
			xmlElement.SetAttribute(SystemDataOperation.SetValueName.RateUnbalance.ToString(), indoorSystem.RateUnbalance.ToString());
			xmlElement.SetAttribute(SystemDataOperation.SetValueName.DPressCapital.ToString(), indoorSystem.DPressCapital.ToString());
			xmlElement.SetAttribute(SystemDataOperation.SetValueName.DPressControl.ToString(), indoorSystem.DPressControl.ToString());
			XmlElement newChild = this.CreateIndoorPipe(indoorSystem.SupplyMPipe, "SupplyPipe");
			xmlElement.AppendChild(newChild);
			XmlElement newChild2 = this.CreateIndoorPipe(indoorSystem.SupplyMPipe, "ReturnPipe");
			xmlElement.AppendChild(newChild2);
			XmlElement newChild3 = this.CreateCircleSystem(indoorSystem.CirclePipes);
			xmlElement.AppendChild(newChild3);
			return xmlElement;
		}

		private XmlElement CreateIndoorPipe(HYPipeData pipeData, string name)
		{
			XmlElement xmlElement = this.xmlDoc.CreateElement(name);
			xmlElement.SetAttribute(SystemDataOperation.SetValueName.Flow.ToString(), pipeData.Flow.ToString());
			xmlElement.SetAttribute(SystemDataOperation.SetValueName.OutDiameter.ToString(), pipeData.OutDiameter.ToString());
			xmlElement.SetAttribute(SystemDataOperation.SetValueName.Length.ToString(), pipeData.Length.ToString());
			xmlElement.SetAttribute(SystemDataOperation.SetValueName.Speed.ToString(), pipeData.Speed.ToString());
			xmlElement.SetAttribute(SystemDataOperation.SetValueName.ResistanceFrict.ToString(), pipeData.ResistanceFrict.ToString());
			xmlElement.SetAttribute(SystemDataOperation.SetValueName.DragForce.ToString(), pipeData.DragForce.ToString());
			xmlElement.SetAttribute(SystemDataOperation.SetValueName.ResistanceLocal.ToString(), pipeData.ResistanceLocal.ToString());
			xmlElement.SetAttribute(SystemDataOperation.SetValueName.Resistance.ToString(), pipeData.Resistance.ToString());
			XmlElement newChild = this.CreatePipeValve(pipeData);
			xmlElement.AppendChild(newChild);
			return xmlElement;
		}

		private XmlElement CreateCircleSystem(IList<CirclePipe> listCirclePipes)
		{
			XmlElement xmlElement = this.xmlDoc.CreateElement("CircleSystems");
			foreach (CirclePipe circlePipe in listCirclePipes)
			{
				XmlElement xmlElement2 = this.xmlDoc.CreateElement("Circle");
				xmlElement2.SetAttribute(SystemDataOperation.SetValueName.Load.ToString(), circlePipe.PipeData.Load.ToString());
				xmlElement2.SetAttribute(SystemDataOperation.SetValueName.Flow.ToString(), circlePipe.Flow.ToString());
				xmlElement2.SetAttribute(SystemDataOperation.SetValueName.OutDiameter.ToString(), circlePipe.PipeData.OutDiameter.ToString());
				xmlElement2.SetAttribute(SystemDataOperation.SetValueName.Length.ToString(), circlePipe.PipeData.Length.ToString());
				xmlElement2.SetAttribute(SystemDataOperation.SetValueName.Speed.ToString(), circlePipe.PipeData.Speed.ToString());
				xmlElement2.SetAttribute(SystemDataOperation.SetValueName.ResistanceFrict.ToString(), circlePipe.PipeData.ResistanceFrict.ToString());
				xmlElement2.SetAttribute(SystemDataOperation.SetValueName.Resistance.ToString(), circlePipe.PipeData.Resistance.ToString());
				xmlElement2.SetAttribute(SystemDataOperation.SetValueName.RateUnbalance.ToString(), circlePipe.RateUnbalance.ToString());
				XmlElement newChild = this.CreatePipeValve(circlePipe.PipeData);
				xmlElement2.AppendChild(newChild);
				xmlElement.AppendChild(xmlElement2);
			}
			return xmlElement;
		}

		private XmlDocument xmlDoc;

		private string rootName = "Building";

		public enum SetValueName
		{
			PreSerialNum,
			SerialNum,
			RateUnbalance,
			Load,
			Flow,
			Diameter,
			OutDiameter,
			Length,
			Speed,
			ResistanceFrict,
			DragForce,
			ResistanceLocal,
			Resistance,
			DPressCapital,
			DPressControl,
			CircleNum,
			IndoorNum,
			Number,
			Height,
			RiserPipeNum
		}

		public enum SettingNodeName
		{
			MainPipe,
			RiserPipe,
			SupplyTemper,
			ReturnTemper,
			FloorNum,
			Floors,
			Floor,
			LocalCoef,
			LocalResist,
			DPCValvePosition,
			PressPCValve,
			PressTCValve
		}

		public enum SystemNodeName
		{
			BuildSystem,
			MSupplyPipes,
			Pipe,
			Valve,
			MReturnPipes,
			ShareRPipes,
			RiserPipe,
			RSupplyPipes,
			RReturnPipes,
			FloorSystems,
			Floor,
			IndoorSystem,
			SupplyPipe,
			ReturnPipe,
			CircleSystems,
			Circle
		}
	}
}
